//
//  CancelTaskTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/20.
//

#import "CancelTaskTableViewCell.h"
#import "YTBaseSelectStringView.h"

@interface CancelTaskTableViewCell ()
@property (nonatomic ,strong) YTBaseSelectStringView * YYview;
@property (nonatomic ,strong) YTBaseSelectStringView * FWview;
@property (nonatomic ,strong) YTBaseSelectStringView * SJview;
@end

@implementation CancelTaskTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.whiteColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    self.contentView.clipsToBounds = YES;
    MJWeakSelf
    YTBaseSelectStringView * YYview = [YTBaseSelectStringView NewView];
    YYview.forceFlag = YES;
    YYview.name = @"取消原因";
    self.YYview = YYview;
    YYview.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openQXYYBlock){
            weakSelf.openQXYYBlock(weakSelf.model);
        }
    };
    [self.contentView addSubview:YYview];
    [YYview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(0);
        make.height.offset(kwt(63));
    }];
    
    
    YTBaseSelectStringView * FWview = [YTBaseSelectStringView NewView];
    FWview.forceFlag = YES;
    FWview.name = @"取消范围";
    self.FWview = FWview;
    FWview.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openQXFWBlock){
            weakSelf.openQXFWBlock(weakSelf.model);
        }
    };
    [self.contentView addSubview:FWview];
    [FWview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.equalTo(YYview.mas_bottom);
        make.height.offset(kwt(63));
    }];
    
    
    YTBaseSelectStringView * SJview = [YTBaseSelectStringView NewView];
    SJview.forceFlag = YES;
    SJview.name = @"取消时间";
    self.SJview = SJview;
    SJview.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openQXSJBlock){
            weakSelf.openQXSJBlock(weakSelf.model);
        }
    };
    [self.contentView addSubview:SJview];
    [SJview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.equalTo(FWview.mas_bottom);
        make.height.offset(kwt(63));
    }];
    
    
    
}

- (void)setModel:(CancelAndTransferModel *)model{
    _model = model;
    self.YYview.content = model.applyReason;
    self.FWview.content = model.cancelRange;
    if(model.cancelStartTime.length < 1 || model.cancelEndTime.length < 1){
        self.SJview.content = @"";
    } else if([model.cancelStartTime isEqualToString:model.cancelEndTime]){
        self.SJview.content = model.cancelStartTime;
    }else{
        self.SJview.content = [NSString stringWithFormat:@"%@-%@~%@-%@",[model.cancelStartTime componentsSeparatedByString:@"-"][1],[model.cancelStartTime componentsSeparatedByString:@"-"].lastObject,[model.cancelEndTime componentsSeparatedByString:@"-"][1],[model.cancelEndTime componentsSeparatedByString:@"-"].lastObject];
    }
}

@end
